package io.renren.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.entity.Shippercode;
import io.renren.entity.SysOrderEntity;
import io.renren.service.SysOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;



/**
 *
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-10 16:11:11
 */
@RestController
@RequestMapping("api/sysorder")
@Api(tags = "订单")
public class SysOrderController {
    @Autowired
    private SysOrderService sysOrderService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation("列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysOrderService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation("根据ID查询订单信息")
    public R info(@PathVariable("id") Integer id){
        SysOrderEntity sysOrder = sysOrderService.getById(id);

        return R.ok().put("sysOrder", sysOrder);
    }


    /**
     * 根据ID查询订单详情
     */
    @GetMapping("/detail/{id}")
    @ApiOperation("根据ID查询订单详情")
    public R  queryDetailById(@PathVariable Integer id) {
        SysOrderEntity sysOrder = sysOrderService.queryDetailById(id);
        return R.ok().put("order", sysOrder);
    }
    /**
     * 根据商户ID查询订单
     */
    @GetMapping("/merchant")
    @ApiOperation("根据商户ID查询订单")
    public R queryMerchantOrders(@RequestParam Map<String, Object> params){
        PageUtils pageUtils = sysOrderService.queryByRetailOrMerchantId(params);

        return R.ok().put("page", pageUtils);
    }

    /**
     * 查询快递类型
     * 1、
     */
    @GetMapping("/express")
    @ApiOperation("查询快递公司")
    public R queryexpressAllApi(){
     List<Shippercode>  expressList= sysOrderService.queryexpressAllApi();
     return R.ok().put("list", expressList);
    }


    /**
     * 卖家点击发货
     * @return
     */
    @PostMapping("/send")
    @ApiOperation("订单发货")
    public R sendOrder(@RequestBody HashMap<String,String> params){
        //更新 订单状态
        sysOrderService.sendOrder(params);
        return R.ok();
    }

    /**
     * 卖家点击拒单
     * @return
     */
    @GetMapping("/sends/{orderId}")
    @ApiOperation("订单拒单")
    public R sendOrders(@PathVariable Integer orderId){
        //更新 订单状态
        sysOrderService.sendOrders(orderId);
        return R.ok();
    }



}
